package com.huluobo.a2302monthdemo.pages

import androidx.compose.foundation.clickable
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import com.blankj.utilcode.util.ToastUtils
import com.huluobo.a2302monthdemo.MineIntent
import com.huluobo.a2302monthdemo.MineViewModel
import com.huluobo.lib_base.UIState
import com.huluobo.lib_base.entity.User
import kotlinx.coroutines.launch

/**
 *  Created by LC on 2025/8/9.
 */

@Composable
fun MinePage(vm: MineViewModel = hiltViewModel()) {
    LaunchedEffect(key1 = "", block = {
        launch {
            vm.state.collect {
                when (it) {
                    is UIState.OnFailed -> {
                        ToastUtils.showLong("注册失败")
                    }

                    UIState.OnLoading -> {}
                    is UIState.OnSuccess<*> -> {
                        ToastUtils.showLong("注册成功:${it.data}")
                    }
                }
            }
        }
    })
    Text(text = "我的", modifier = Modifier.clickable {
        val user = User(username = "lc", password = "123", role = 1)
        vm.sendIntent(MineIntent.Register(user))
    })
}